import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { TypeOrmModule } from '@nestjs/typeorm';
import { UsersModule } from './users/users.module';
import { CategoryModule } from './category/category.module';
import { VideoModule } from './video/video.module';
import { VideoItemModule } from './video-item/video-item.module';
import { BannerModule } from './banner/banner.module';

import config from '../config';

import { Banner } from './banner/banner.entity';
import { User } from './users/user.entity';
import { AuthModule } from './auth/auth.module';
import { Category } from './category/category.entity';
import { Video, VideoCategory } from './video/video.entity';
import { VideoItem, VideoItemUser } from './video-item/video-item.entity';

const { host, username, password, database } = config;
const mySqlModule = TypeOrmModule.forRoot({
  type: 'mysql',
  host,
  port: 3306,
  username,
  password,
  database,
  entities: [
    User,
    Category,
    Video,
    VideoCategory,
    VideoItem,
    VideoItemUser,
    Banner,
  ],
  synchronize: true,
});

@Module({
  imports: [
    mySqlModule,
    UsersModule,
    AuthModule,
    CategoryModule,
    VideoModule,
    VideoItemModule,
    BannerModule,
  ],
  exports: [TypeOrmModule],
  providers: [AppService],
  controllers: [AppController],
})
export class AppModule {}
